home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / _SQLite_Display2DResult.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  55 lines

  1. #include <SQLite.au3>
  2. #include <SQLite.dll.au3>
  3.  
  4. Local $aResult, $iRows, $iColumns, $iRval
  5.  
  6. _SQLite_Startup ()
  7. If @error > 0 Then
  8.     MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
  9.     Exit - 1
  10. EndIf
  11. _SQLite_Open () ; Open a :memory: database
  12. If @error > 0 Then
  13.     MsgBox(16, "SQLite Error", "Can't Load Database!")
  14.     Exit - 1
  15. EndIf
  16.  
  17. ;Example Table
  18. ;     Name        | Age
  19. ;     -----------------------
  20. ;     Alice       | 43
  21. ;     Bob         | 28
  22. ;     Cindy       | 21
  23.  
  24. If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
  25.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  26. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
  27.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  28. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
  29.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  30. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
  31.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  32.  
  33. ; Query
  34. $iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
  35. If $iRval = $SQLITE_OK Then
  36.     _SQLite_Display2DResult($aResult)
  37.  
  38. ;~       $aResult looks like this:
  39. ;~  
  40. ;~      Name   Age 
  41. ;~      Alice  43  
  42. ;~      Bob    28  
  43. ;~      Cindy  21  
  44. ;~
  45. ;~    If the dimensions would be switched in _SQLite_GetTable2d the result would look like this:
  46. ;~  
  47. ;~      Name  Alice  Bob  Cindy 
  48. ;~      Age   43     28   21    
  49.  
  50. Else
  51.     MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
  52. EndIf
  53.  
  54. _SQLite_Close ()
  55. _SQLite_Shutdown ()